<?php

namespace App\Admin\Controllers;

use App\model\panyuan\WorkshopYuyue;
use App\model\Workshop;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class WorkshopYuyueController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '预约看厂列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new WorkshopYuyue());

        $grid->column('id', __('Id'));
        $grid->column('name', __('申请人姓名'));
        $grid->column('mobile', __('手机号'));
        $grid->column('workshop_id', __('盘源'))->display(function($value){
            return Workshop::find($value)->title ?? '';
        });
        $grid->column('start_time', __('开始时间'));
        $grid->column('end_time', __('结束时间'));
        $grid->column('created_at', __('创建时间'));


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(WorkshopYuyue::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('mobile', __('Mobile'));
        $show->field('workshop_id', __('Workshop id'));
        $show->field('start_time', __('Start time'));
        $show->field('end_time', __('End time'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new WorkshopYuyue());

        $form->text('name', __('Name'));
        $form->mobile('mobile', __('Mobile'));
        $form->number('workshop_id', __('Workshop id'));
        $form->text('start_time', __('Start time'));
        $form->text('end_time', __('End time'));

        return $form;
    }
}
